#!/bin/bash

# 启动 daemon 程序
script_path=$(dirname "$0")
SERVICE_FILE="$script_path/service_output.txt"
ionice -c 2 -n 0 nice -n -20 ../../bin/*mon 2>&1 | tee $SERVICE_FILE & 

# 循环检查打屏信息
for i in {1..10000}; do  # 循环 10 次
    if tail -n 1 $SERVICE_FILE | grep -q "Daemon start success!"; then
        echo "Daemon start success"
        break
    fi
    if tail -n 1 $SERVICE_FILE | grep -q "ERR: Failed to init endpoint! Please check the service log or console output."; then
        # while [ $count -lt 2 ]; then
        # do
            # ((count++))
            rm $SERVICE_FILE
            pkill -9 mind
            bash $script_path/start_daemon.sh
        # done
    fi
    sleep 2
done
